<?php

/**
 * ECSHOP 飞印管理程序
 * ============================================================================
 * 版权所有 2005-2010
 * 网站地址: http://www.feyin.net；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: chenjunhui $
 * $Id: feyin.php 63 2010-11-18 16:30:46Z chenjunhui $
 */

define('IN_ECS', true);

require(dirname(__FILE__) . '/includes/init.php');
include_once(ROOT_PATH . 'includes/lib_feyin.php');

/* 检查安装 */
if (file_exists(ROOT_PATH . '/install_feyin.php')) {
	$feyin_warning[] = $_LANG['feyin_warning'];
    $smarty->assign('warning_arr', $feyin_warning);
	$smarty->display('feyin.htm');
	exit;
}

$exc = new exchange($ecs->table('feyin'), $db, 'feyin_id', 'feyin_account');

/*
 * 编辑飞印 API接口信息
 * ?act=edit
 */
if ($_REQUEST['act'] == 'edit') {
	admin_priv("feyin");

	if (strlen(listDevice()) > 10) {
		$deviceStatusXML = new SimpleXMLElement(listDevice());
		$deviceStatus = getDevice($deviceStatusXML);
	}
	
	$feyin_switch = $exc->get_name(1,'feyin_switch');
	($feyin_switch)?$feyin_switch_yes='checked="checked"':$feyin_switch_fail='checked="checked"';
	$feyin_API = $exc->get_name(1,'feyin_API');
	$feyin_code = $exc->get_name(1,'feyin_code');
	$feyin_deviceNo = $exc->get_name(1,'feyin_deviceNo');
	$feyin_printf_number = $exc->get_name(1,'feyin_printf_number');
	$before_feyin_log = $exc->get_name(1, 'feyin_log');
	$feyin_log = explode(";", $before_feyin_log);
	array_pop($feyin_log);
	
    $smarty->assign('ur_here', $_LANG['feyin_settings']);
    $smarty->assign('feyin_switch', $feyin_switch);
    $smarty->assign('feyin_switch_yes', $feyin_switch_yes);
    $smarty->assign('feyin_switch_fail', $feyin_switch_fail);
    $smarty->assign('feyin_device', $deviceStatus);
    $smarty->assign('feyin_API', $feyin_API);
    $smarty->assign('feyin_code', $feyin_code);
    $smarty->assign('feyin_deviceNo', $feyin_deviceNo);
	$smarty->assign('feyin_printf_number', $feyin_printf_number);
    $smarty->assign('feyin_log', $feyin_log);
	$smarty->display('feyin.htm');
} elseif ($_REQUEST['act'] == 'save_config' && isset($_POST)) {
	/*
	 * 保存飞印API接口信息
	 * ?act=save_config
	 */
	admin_priv("feyin");

	$feyin_switch=$_POST['feyin_switch'];
	$feyin_API = $_POST['feyin_API'];
	$feyin_code = $_POST['feyin_code'];
	$feyin_deviceNo = $_POST['feyin_deviceNo'];
	$feyin_printf_number = $_POST['feyin_printf_number'];
	$exc->edit("feyin_switch=".'\''.$feyin_switch.'\'', 1);
	$exc->edit("feyin_API=".'\''.$feyin_API.'\'', 1);
	$exc->edit("feyin_code=".'\''.$feyin_code.'\'', 1);
	$exc->edit("feyin_deviceNo=".'\''.$feyin_deviceNo.'\'', 1);
	$exc->edit("feyin_printf_number=".'\''.$feyin_printf_number.'\'', 1);
	
	sys_msg($_LANG['save_ok'], 0, array(array('href'=>'feyin.php?act=edit', 'text'=>$_LANG['feyin_settings'])));
} elseif ($_REQUEST['act'] == 'clean_log') {
	$exc->edit('feyin_log=""', 0);
	sys_msg($_LANG['clean_log_ok'], 0, array(array('href'=>'feyin.php?act=edit', 'text'=>$_LANG['feyin_settings'])));
}
?>
